﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookingHotel.ClasseDiDominio;

namespace BookingHotel.Collezioni
{
    class RoomsCollection
    {
        private List<SameRoom> _roomsList = new List<SameRoom>();

        public void AddRoom(SameRoom newRoom)
        {
            if (_roomsList.Find(period => period.Id == newRoom.Id) == null)
                _roomsList.Add(newRoom);
            else
                throw new Exception("Duplicate id for client.");
        }

        public void AddRoom(string type, int capacity, decimal price, int quantity)
        {
            int idOfNewRoom = _roomsList.Count;
            SameRoom newRoom = new SameRoom(type, capacity, price, quantity, idOfNewRoom);
            AddRoom(newRoom);
        }

        public SameRoom GetRoomById(int RoomId)
        {
            return _roomsList.Find(r => r.Id == RoomId);
        }

        public String ToString()
        {
            String allRoomToString = "";
            foreach (SameRoom currentRoom in _roomsList)
                allRoomToString += currentRoom.ToString();
            return allRoomToString;
        }

        public int GetQuantityOfThisTypeRoom(string typeRoom)
        {
            SameRoom thisSameRoom = _roomsList.Find(r => r.Type == typeRoom);
            if (thisSameRoom == null)
                return 0;
            else
                return thisSameRoom.Quantity;
        }

        public decimal GetPriceOfThisRoom(string typeRoom)
        {
            SameRoom thisSameRoom = _roomsList.Find(r => r.Type == typeRoom);
            if (thisSameRoom == null)
                throw new NotImplementedException();
            else
                return thisSameRoom.Price;
        }


    }
}
